package T900;

import java.util.HashMap;

/**
 * @Author cheng.song
 * @create 2022/1/27 15:31
 */
public class 有序数组的平方977 {

    public static void main(String[] args) {
        int[] nums = new int[]{-4,-1,0,3,10};
        for (int i : sortedSquares(nums)) {
            System.out.println(i);
        }
    }

    public static int[] sortedSquares(int[] nums) {
        int[] result = new int[nums.length];
        int end = nums.length-1;
        int left =0;
        int right = nums.length-1;
        while (left<=right){
            if(Math.abs(nums[left])>Math.abs(nums[right])){
                result[end--]= nums[left]*nums[left];
                left++;
            }else{
                result[end--]= nums[right]*nums[right];
                right--;
            }
        }
        return result;
    }

}
